﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;

namespace DAO
{
    public class MonAnDAO
    {
        public static DataTable ListMonan(int Loai)
        {
            string sql = string.Format("select m.MAMONAN,m.TENMON,m.DONGIA,m.MADONVI,m.MALOAI,dv.TENDONVI from MONAN as m,DONVITINH as dv where m.MALOAI={0} and m.MADONVI=dv.MADONVI ", Loai);
            return DataProvider.ExcuteQuery(sql);
        }
        public static int Themmon(MonAnDTO mon)
        {
            string sql = string.Format("insert into MONAN(MADONVI,TENMON,DONGIA,MALOAI) values ('{0}',N'{1}','{2}','{3}')", mon.Madv, mon.Tenmon, mon.Dongia, mon.Maloai);
            return DataProvider.ExcuteNonQuery(sql);
        }
        public static int Xoamon(int Mamon)
        {
            string sql = string.Format("delete MONAN where MAMONAN='{0}'", Mamon);
            return DataProvider.ExcuteNonQuery(sql);
        }
        public static int Capnhatmon(MonAnDTO mon)
        {
            string sql = string.Format("update MONAN set MADONVI='{0}',TENMON='{1}',DONGIA='{2}',MALOAI='{3}' where MAMONAN='{4}'", mon.Madv, mon.Tenmon, mon.Dongia, mon.Maloai, mon.Mamon);
         
            return DataProvider.ExcuteNonQuery(sql);
        }
        public static int CheckNull(int mamon)
        {
            string sql = string.Format("select * from CHITIETDATMON where MAMONAN={0}", mamon);
            DataTable dt = DataProvider.ExcuteQuery(sql);
            if (dt != null)
            {
                return 1;
            }
            return 0;

        }
        
        
    }
}
